import java.util.HashMap;

public class map {
    public int[] twoSum(int[] nums, int target) {
        HashMap<Integer, Integer> map = new HashMap<>();//存放数组中的元素以及对应的下标
        int[] ret = new int[2];
        int len = nums.length;
        for (int i = 0; i < len; i++) {
            int num = map.getOrDefault(target - nums[i], -1);
            if (num == -1) {
                map.put(nums[i], i);
            } else {
                ret[0] = i;
                ret[1] = num;
            }
        }
        return ret;
    }
}
